package com.wyw.springcloud.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheKey;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult;
import com.wyw.springcloud.common.bean.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 文件介绍
 *
 * @Author： Mr Wu （yewen.wu.china.gmail.com）
 * @Date: 2020/9/30 16:04
 */
@Slf4j
@Service
public class RequestCacheService {

    @Resource
    private MyService service;//为什么要用MyService，因为MyService继承IService，如果注入IService，将会不知道究竟是哪个，也可以用Primary指定，单是需要指定的就特别多

    @CacheResult
    @HystrixCommand(commandKey = "cacheKey")
    public Student requestCache(@CacheKey String name){
        log.info("request cache " + name);
        Student student = new Student();
        student.setName(name);
        student = service.sayHiPost(student);
        log.info("after requesting cache " + name);
        return student;
    }
}
